package com.xxgc.eow.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.xxgc.eow.result.Result;

import java.time.LocalDateTime;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.xxgc.eow.service.ICompanytopicService;
import com.xxgc.eow.entity.Companytopic;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 企业题目 前端控制器
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-06-04
 */
@Tag(name = "企业题目")
@RestController
@RequestMapping("/companytopic")
public class CompanytopicController {

    @Resource
    private ICompanytopicService companytopicService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "查询所有接口", description = "查询企业题目所有数据")
    @SaIgnore
    @GetMapping
    public Result<List<Companytopic>> findAll() {
        return Result.ok(companytopicService.list());
    }

    /**
     * 根据id查询数据接口
     * @param id
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "根据ComapnyId查询数据接口", description = "根据ComapnyId查询数据接口")
    @Parameters({
            @Parameter(name = "id",description = "组件id",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/{id}")
    public Result<List<Companytopic>> findOne(@PathVariable Integer id) {
        return Result.ok(companytopicService.getAll(id));
    }

    /**
     * 根据id查询数据接口
     * @param libraryId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "根据libraryId查询数据接口", description = "根据libraryId查询数据接口")
    @Parameters({
            @Parameter(name = "libraryId",description = "libraryId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("library/{libraryId}")
    public Result<List<Companytopic>> findtwo(@PathVariable Integer libraryId) {
        return Result.ok(companytopicService.getBylibraryId(libraryId));
    }

    /**
     * 新增和更新接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "新增", description = "新增")
    @SaIgnore
    @PostMapping
    public Result save(@RequestBody Companytopic companytopic) {
        companytopicService.add(companytopic);
        return Result.ok();
    }

    /**
     * 删除接口
     * @param topicLibraryId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "删除接口", description = "通过topicLibraryId和companyId删除")
    @Parameters({
            @Parameter(name = "topicLibraryId",description = "companyId",required = true,in=ParameterIn.QUERY),
            @Parameter(name = "companyId",description = "companyId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/del")
    public Result delete(@Parameter Integer topicLibraryId,@Parameter Integer companyId) {
        Companytopic companytopic = new Companytopic();
        companytopic.setCompanyId(companyId);
        companytopic.setTopicLibraryId(topicLibraryId);
        companytopic.setDestroyTime(LocalDateTime.now());
        companytopic.setTip(1);
        companytopicService.updat(companytopic);
        return Result.ok();
    }




}